package org.springcloud.wisdom.springcloud_03_freshman.student.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springcloud.wisdom.springcloud_03_freshman.student.entity.Paid;

import javax.print.attribute.standard.Sides;
import java.util.List;

@Mapper
public interface PaidDao {
    //根据sid查缴费记录
    @Select("select * from paid where sno=#{sno}")
    public List<Paid> getPaids(String sno);
    @Select("select * from paid where sno=#{sno}")
    public Paid getPaidBySno(String sno);
    //更新付款时间以及付款状态 订单号
    @Update("update paid set payno=#{payno},paydt=#{paydt},status=#{status} where sno=#{sno}")
    public int updatePaidBySno(Paid paid);

    //根据不同的条件查询
    @Select("<script>" +
            "select * from paid" +
            "  <where>" +
            "    <if test=\"sno != null\">" +
            "      sno = #{sno}" +
            "    </if>" +
            "    <if test=\"status != null\">" +
            "        and  status = #{status} " +
            "    </if>" +
            "    <if test=\"sdept != null\">" +
            "        and  sdept = #{sdept} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")
    public List<Paid> getPaidCons(int start,int size,String sno,String status,Integer sdept);
    @Select("<script>" +
            "select count(*)  from paid" +
            "  <where>" +
            "    <if test=\"sno != null\">" +
            "      sno = #{sno}" +
            "    </if>" +
            "    <if test=\"status != null\">" +
            "        and  status = #{status} " +
            "    </if>" +
            "    <if test=\"sdept != null\">" +
            "        and  sdept = #{sdept} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public int countPaid(String sno,String status,Integer sdept);

    //删除一个
    @Delete("delete from paid WHERE sno=#{sno}")
    public int delPaidBySno(String sno);
    //删除多个
    @Delete("<script>" +
            "  delete from paid where sno in" +
            "  <foreach collection=\"ids\" item=\"did\" open=\"(\" close=\")\" separator=\",\">" +
            "    #{did}" +
            "   </foreach>" +
            "</script>")
    public int delPaidbySnos(List<Integer> ids);
}
